##Table 5 - Run OLS regressions to estimate ATE of experiment
#variable consequences captures which version of question assigned
#consequences = 0 is "The use of force is justified to restore Donald Trump to the presidency"
#consquences=1 adds [, even if some people are injured or killed]. 

#run OLS model 1, no controls
T5A<-svyglm(tf~consequences,design=nd, family = gaussian(identity))

#run OLS model 2, add controls
T5B<-svyglm(tf~consequences+gender+as.factor(racethnicity)+age,design=nd, family = gaussian(identity))

#summarize results, OLS model 1 (no controls)
S5A<-summary(T5A)

#summarize results, OLS model 2 (with controls)
S5B<-summary(T5B)

#condense summaries for each model
T5C1<-round(rbind(S5A$coefficients[2,1],S5A$coefficients[2,2],S5A$coefficients[2,4]),3)
T5C2<-round(rbind(S5B$coefficients[2,1],S5B$coefficients[2,2],S5B$coefficients[2,4]),3)

#bind condensed summaries together
T5R13<-cbind(T5C1,T5C2)

#add a row stating controls
T5R4<-c("None","Gender,Race,Age")

#add a row stating number of observations
T5R5<-c(3145,3145)

#bind these all together
t5<-as.data.frame(rbind(T5R13,T5R4,T5R5))

#rename the rows to be more interpretable
rownames(t5)<-c("Estimated Average Treatment Effect (ATE)","Standard Error","P-value","Controls","obs")

#rename the columns to be more interpretable
colnames(t5)<-c("OLS Model 1","OLS Model 2")

#write out results
write.csv(t5,"../Main Results/T5.csv")

#Alternatively, you can see regression results in a conventional tabular format
stargazer(T5A,T5B, type="text", style="apsr",omit=c("gender","age","racethnicity","Constant"),omit.stat=c("ll","aic"), out="../Main Results/T5-Stargazer.html")